package com.ppafl;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class StandingAdapter extends ArrayAdapter<TeamStatistic> {

	Context mcontext;
	int layoutResourceId;
	List<TeamStatistic> teams;
	
	public StandingAdapter(Context context, int textViewResourceId,
			List<TeamStatistic> objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
		mcontext = context;
		layoutResourceId = textViewResourceId;
		teams = objects;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View row = convertView;
		TeamHolder holder = null;
		
		if(row == null){
			LayoutInflater inflater = ((Activity) mcontext).getLayoutInflater();
			row = inflater.inflate(layoutResourceId, parent, false);
			
			holder = new TeamHolder();
			//holder.teamName = (TextView) row.findViewById(0);
			
			row.setTag(holder);
			
		}else{
			holder = (TeamHolder) row.getTag();
		}
		TeamStatistic cteam = teams.get(position);
		holder.teamName.setText(cteam.name);
		holder.pts.setText(String.valueOf(cteam.pts));
		
		//return super.getView(position, convertView, parent);
		return row;
	}
	
	static class TeamHolder{
		TextView teamName;
		TextView pts;
	}

}
